﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Swaf.BizObj;
using eCom;

namespace NewGui.std
{
	public partial class AfterExternalPayment : Syrinx.Gui.AspNet.Ajax.NitobiBasePage
	{
		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
			IPaymentProcessingBizProc paymentManProc = null;
			IBizObj paymentDetails = null;
			PaymentProcessResults prc = PaymentProcessResults.paymentFailure;

			paymentManProc = paypal.TheBizProc as IPaymentProcessingBizProc;
			if (payment != null && paymentManProc.isOrderUsingPayment)
			{
				prc = paymentManProc.validatePaymentProcessing();
				paymentDetails = paypal.TheBizProc.CurrentBizObj;
			}

			if (prc == PaymentProcessResults.paymentSuccess && paymentDetails != null)
				payment.TheBizProc.updateBizObj(paymentDetails);

			if (prc == PaymentProcessResults.paymentSuccess)
			{
				//This move next is to get past the check outpage.  The given payment processing bizproc should have
				//setup the stepComplete for check out.
				checkout.TheBizProc.Actions["MoveNextNoNav"].trigger(); 
				//Because this is an external processing payment, we will step complete the paymentinfo step here
				checkout.TheBizProc.CurrentBizObj.put("stepCompleted", true);
			}

			//Wether the external payment processing was successful or not, we need to move off of this page
			//if the payment was not successful, the page will be checkout complete.  If the payment was successful
			//then the checkout step and the paymentinfo step would have been marked complete and ready to move to check out complete.
			checkout.TheBizProc.Actions["MoveNext"].trigger();
		}
	}
}
